﻿@using Website.CRUDServices
@using Website.Models.Styling
@using Location = Website.Models.Domain.Location
@model Website.Models.ViewModels.ListView<ProjectMeeting>
@{
    this.ViewBag.Title = "Projekter";
    this.Layout = "~/Views/_Shared/_Layout.cshtml";
    var locations = this.ViewData["Locations"] as List<Location> ?? new List<Location>();
    var projectMeetingTypes = this.ViewData["ProjectMeetingTypes"] as List<ProjectType> ?? new List<ProjectType>();
    var projectMeetingDemonstrations = this.ViewData["ProjectMeetingDemonstrations"] as List<ProjectMeetingDemonstration> ?? new List<ProjectMeetingDemonstration>();
    var projectMeetingRoles = this.ViewData["ProjectMeetingRoles"] as List<ProjectMeetingRole> ?? new List<ProjectMeetingRole>();
    DefaultSearchFields defaultFields = this.ViewData["DefaultFields"] as DefaultSearchFields ?? new DefaultSearchFields();
    var criteriaLocation = this.ViewData["CriteriaLocation"] as Guid?;
    var criteriaProjectType = this.ViewData["CriteriaProjectType"] as Guid?;
    var criteriaProjectDemonstration = this.ViewData["CriteriaProjectDemonstration"] as Guid?;
    var criteriaProjectRole = this.ViewData["CriteriaProjectRole"] as Guid?;
    var criteriaStatusType = this.ViewData["CriteriaStatusType"] as ProjectMeetingStatusType? ?? ProjectMeetingStatusType.None;
}
<h2>Søgeresultat - @ViewBag.Title</h2>

<fieldset class="searchCriterias">
    <legend>Søgning</legend>
    <table>    
        <tr>
            <td>Type:</td><td>@ViewBag.Title</td>
        </tr>
        <tr><td>Antal resultater i alt: </td><td>@Model.TotalRows</td></tr>
        @if (criteriaLocation.HasValue && criteriaLocation.Value != Guid.Empty)
        {
            <tr><td>Lokation: </td><td>@locations.Single(x => x.ID == criteriaLocation.Value).Name</td></tr>
        }
        
            <tr><td>Status: </td>
                <td>
                    @if (criteriaStatusType == ProjectMeetingStatusType.None){ @Html.Raw("Alle")}
                    @if (criteriaStatusType == ProjectMeetingStatusType.NotStarted){ @Html.Raw("Ikke startet")}
                    @if (criteriaStatusType == ProjectMeetingStatusType.Started){ @Html.Raw("Startet")}
                    @if (criteriaStatusType == ProjectMeetingStatusType.Completed){ @Html.Raw("Færdigt")}
                    
                                 
                </td>
            </tr>
        
        
        @if (criteriaProjectType.HasValue && criteriaProjectType.Value != Guid.Empty)
        {
            var pt = projectMeetingTypes.Single(x => x.ID == criteriaProjectType.Value);
            <tr><td>Projekt type: </td><td>@Html.Raw(string.Format("({0}) {1}", pt.IsResearchAndDevelopment ? "R&D" : "Ikke R&D", pt.Name))</td></tr>
        }
        @if (criteriaProjectDemonstration.HasValue && criteriaProjectDemonstration.Value != Guid.Empty)
        {
            <tr><td>Demonstration: </td><td>@projectMeetingDemonstrations.Single(x => x.ID == criteriaProjectDemonstration.Value).Name</td></tr>
        }
        @if (criteriaProjectRole.HasValue && criteriaProjectRole.Value != Guid.Empty)
        {
            <tr><td>WT Rolle: </td><td>@projectMeetingRoles.Single(x => x.ID == criteriaProjectRole.Value).Name</td></tr>
        }
        @Html.Partial("~/Views/Reports/_SearchDefaultFieldsParametersTableTR.cshtml", defaultFields)

    </table>
</fieldset>


<table class="tableView tableWithOnlyLastChild">
    <tr>
        @foreach (TableViewHeaderItem item in this.Model.Header.Items)
        {
            <td>
                @Html.Partial("~/Views/_Shared/TableViewHeader.cshtml", item)
            </td>
        }
        <td></td>
    </tr>
   @if (this.Model != null)
    {
        foreach (ProjectMeeting meeting in this.Model.List)
        {
        <tr>
            <td>@string.Format("{0:dd-MM-yyyy}", meeting.Date)</td>
            <td>
                @meeting.Name
            </td>
            <td>
                @if(meeting.Status.StatusType == ProjectMeetingStatusType.NotStarted)
                {
                    <label>Ikke påbegyndt</label>
                }
                else if(meeting.Status.StatusType == ProjectMeetingStatusType.Started)
                {
                    <label>Påbegyndt</label>
                }
                else if(meeting.Status.StatusType == ProjectMeetingStatusType.Completed)
                {
                    <label>Færdigt</label>
                }
            </td>
            <td>
                @if (meeting.Status.Roles != null && meeting.Status.Roles.Any())
                {
                    foreach (var role in projectMeetingRoles.Where(x => meeting.Status.Roles.Contains(x.ID)).OrderBy(x => x.Name))
                    {
                        @role.Name
                        <br />
                    }
                }
            </td>
            
                <td>
                    <a href="@Url.Action("ViewProject", "Projects", new { Id = meeting.ID })" target="@meeting.ID.ToString()">
                              <img src="@Url.Content("~/Content/ButtonIcons/notepad_blue.png")" alt="Link"/></a>
                </td>
        </tr>
        }
        <tr><td colspan="@(1+ Model.Header.Items.Count())"></td></tr>
    }
    </table>